package smdc.order.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import smdc.common.annotation.Log;
import smdc.common.core.controller.BaseController;
import smdc.common.core.domain.AjaxResult;
import smdc.common.enums.BusinessType;
import smdc.order.domain.DiningTable;
import smdc.order.service.IDiningTableService;
import smdc.common.utils.poi.ExcelUtil;
import smdc.common.core.page.TableDataInfo;

/**
 * 桌位Controller
 * 
 * @author ruoyi
 * @date 2025-03-27
 */
@RestController
@RequestMapping("/order/table")
public class DiningTableController extends BaseController
{
    @Autowired
    private IDiningTableService diningTableService;

    /**
     * 查询桌位列表
     */
    @PreAuthorize("@ss.hasPermi('order:table:list')")
    @GetMapping("/list")
    public TableDataInfo list(DiningTable diningTable)
    {
        startPage();
        List<DiningTable> list = diningTableService.selectDiningTableList(diningTable);
        return getDataTable(list);
    }

    /**
     * 导出桌位列表
     */
    @PreAuthorize("@ss.hasPermi('order:table:export')")
    @Log(title = "桌位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DiningTable diningTable)
    {
        List<DiningTable> list = diningTableService.selectDiningTableList(diningTable);
        ExcelUtil<DiningTable> util = new ExcelUtil<DiningTable>(DiningTable.class);
        util.exportExcel(response, list, "桌位数据");
    }

    /**
     * 获取桌位详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:table:query')")
    @GetMapping(value = "/{tableId}")
    public AjaxResult getInfo(@PathVariable("tableId") Long tableId)
    {
        return success(diningTableService.selectDiningTableByTableId(tableId));
    }

    /**
     * 新增桌位
     */
    @PreAuthorize("@ss.hasPermi('order:table:add')")
    @Log(title = "桌位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DiningTable diningTable)
    {
        return toAjax(diningTableService.insertDiningTable(diningTable));
    }

    /**
     * 修改桌位
     */
    @PreAuthorize("@ss.hasPermi('order:table:edit')")
    @Log(title = "桌位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DiningTable diningTable)
    {
        return toAjax(diningTableService.updateDiningTable(diningTable));
    }

    /**
     * 删除桌位
     */
    @PreAuthorize("@ss.hasPermi('order:table:remove')")
    @Log(title = "桌位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tableIds}")
    public AjaxResult remove(@PathVariable Long[] tableIds)
    {
        return toAjax(diningTableService.deleteDiningTableByTableIds(tableIds));
    }
}
